package com.quantdo.demo;

import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;

import com.quantdo.client.ApplicationActionBarAdvisor;
import com.quantdo.demo.action.OpenNavigatorAction;
import com.quantdo.demo.action.OpenTomcatManageAction;
import com.quantdo.menu.TomcatManageNewAction;

public class IndexApplicationActionBarAdvisor {

	private IWorkbenchAction windowAction;
	private IWorkbenchAction exitAction;
	private IWorkbenchAction perspectiveAction;
	private IWorkbenchAction aboutAction;
	private IWorkbenchAction preferences;
	private IContributionItem contributionItem;
	private OpenNavigatorAction navigatorAction;
	private OpenTomcatManageAction tomcatManageAction;
	private TomcatManageNewAction tomcatManageNewAction;
	
	public void makeActions(ApplicationActionBarAdvisor barAdvisor, IWorkbenchWindow window) {
		//新窗口
		//windowAction = ActionFactory.OPEN_NEW_WINDOW.create(window);
		//barAdvisor.register(windowAction);
		//退出
		exitAction = ActionFactory.QUIT.create(window);
		barAdvisor.register(exitAction);
		//透视图
		//perspectiveAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG.create(window);
		//barAdvisor.register(perspectiveAction);
		//关于
		//aboutAction = ActionFactory.ABOUT.create(window);
		//barAdvisor.register(aboutAction);
		//显示视图列表
		//contributionItem = ContributionItemFactory.VIEWS_SHORTLIST.create(window);

		//preferences = ActionFactory.PREFERENCES.create(window);
		//barAdvisor.register(preferences);
		
		//navigatorAction = new OpenNavigatorAction(window);
		//navigatorAction.setEnabled(true);
		
		tomcatManageAction = new OpenTomcatManageAction(window);
		tomcatManageNewAction = new TomcatManageNewAction(window);
		try {
			//window.getActivePage().openEditor(OpenTomcatManageAction.EDITOR_INPUT,TomcatManageEditor.class.getName());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void fillMenuBar(ApplicationActionBarAdvisor barAdvisor,IMenuManager menuBar) {
		//MenuManager fileMenu = new MenuManager("&File",IWorkbenchActionConstants.M_FILE);
		//fileMenu.add(exitAction);
		//menuBar.add(fileMenu);

		MenuManager windowMenu = new MenuManager("&Window", "Window");
		//MenuManager showMenu = new MenuManager("&Show View", "show view");
		//showMenu.add(contributionItem);

		//windowMenu.add(showMenu);
		//windowMenu.add(navigatorAction);
		windowMenu.add(tomcatManageAction);
		
		windowMenu.add(tomcatManageNewAction);

		//windowMenu.add(new LoginAction());

		menuBar.add(windowMenu);
	}

	public void fillCoolBar( ApplicationActionBarAdvisor applicationActionBarAdvisor, ICoolBarManager coolBar) {
		IToolBarManager fileBarManager = new ToolBarManager(SWT.FLAT|SWT.LEFT|SWT.SHADOW_OUT);
		fileBarManager.add(exitAction);
		//fileBarManager.add(exitAction);
		//coolBar.add(fileBarManager);
		//fileBarManager.update(true);
		
//		IToolBarManager windowBarManager = new ToolBarManager(coolBar.getStyle());
//		windowBarManager.add(exitAction);
//		coolBar.add(windowBarManager);
	}

}
